﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace TripleMatch
{
    public class MainSceneUI : MonoBehaviour
    {
        [SerializeField] private Button m_buttonShop;
        [SerializeField] private Button m_buttonShare;
        [SerializeField] private Button m_buttonSound;
        [SerializeField] private Button m_buttonGuide;
        [SerializeField] private Button m_buttonStartGame;

        [SerializeField] private Button m_buttonModeSwitch;
        [SerializeField] private GameObject m_buttonContainer;

        [SerializeField] private DecorationsGroup decorationsGroup;

        // Start is called before the first frame update
        void Start()
        {
            m_buttonShop.onClick.AddListener(OnClickShop);
            m_buttonShare.onClick.AddListener(OnClickShare);
            m_buttonSound.onClick.AddListener(OnClickSound);
            m_buttonGuide.onClick.AddListener(OnClickGuide);
            m_buttonStartGame.onClick.AddListener(OnClickStartGame);

            m_buttonModeSwitch.onClick.AddListener(OnClickModeSwitch);

            InitMainScene();
        }

        private void InitMainScene()
        {
            //初始化装饰物显示
            decorationsGroup.InitDecorations((switchToEdit)=> {
                m_buttonContainer.SetActive(!switchToEdit);
            });
        }

        private void OnClickModeSwitch()
        {
            m_buttonContainer.SetActive(!m_buttonContainer.activeSelf);
        }

        private void OnClickGuide()
        {
            //TODO 弹出引导弹窗 
            //引导一：切换主页模式和全屏展示模式，单击切换主页和全屏模式，主页显示按钮/全屏模式不显示按钮
            //引导二：长按装饰物进入编辑模式，进入编辑模式后物品右上角会出现减号标记，点击后会在编辑场景中删除该装饰物；
            //              长按后可以使用手指拖动的方式编辑装饰物的位置；
            //              右下角显示仓库按钮，点击后显示当前拥有的装饰物以及对应的数量，点击后会在编辑场景中加入该装饰物；
            //              右小角显示❌✔按钮，点击❌会恢复编辑前场景，点击对号✔会保存该场景
            //引导三：通过过关可以获得装饰品碎片，在商店界面可以兑换对应的装饰物
        }

        private void OnClickStartGame()
        {
            LevelManager.S.StartGame();
        }

        private void OnClickSound()
        {
            //TODO 音效模块的开关，需要找到按钮点击音效，背景音效，胜利音效，装饰物获得音效
        }

        private void OnClickShare()
        {
            SDKManager.S.Share();
        }

        private void OnClickShop()
        {
            UIManager.S.OpenShopUI();
        }
    }
}

